package L628;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @program: javase
 * @description:
 * @author: luolidong
 * @create: 2021-06-30 17:56
 * @version: 1.0
 */
public class Demo {
    public int equalSubstring(String s, String t, int maxCost) {
        if (s.equals(t)) return s.length();
        // 1 1 1 1
        List<Integer> list = new ArrayList<>();
        for (int i = 0, j = 0; i < s.length() && j < t.length(); i++, j++) {
            int temp = Math.abs(s.charAt(i) - t.charAt(j));
            System.out.println(temp);
            list.add(temp);
        }
        Collections.sort(list);
        int count = 0;
        for (int n : list) {
            if (n == 0) {
                count++;
            } else {
                maxCost -= n;
                count++;
            }
            if (maxCost < 0) {
                count--;
                break;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        int i = new Demo().equalSubstring("krrgw",
                "zjxss",
                19);
        System.out.println(i);
    }
}
